<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
<link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel="stylesheet">
<script src="${pageContext.request.contextPath}/js/jquery-1.7.2.js"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
<link href="${pageContext.request.contextPath}/themes/material/easyui.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/themes/icon.css" rel="stylesheet">
<script src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
<title>Insert title here</title>
</head>
<script type="text/javascript">
$(function(){
	//配置搜索框
	$('#searchEmp').searchbox({
		searcher : function(value, name) {
			var uname = value;
			$('#empMsg').datagrid('reload', {
				searchname : uname
			});
		}
	});
	
	//默认增加对话框是关闭的
	$('#addEmp').dialog('close');
	//默认更新对话框是关闭的
	$('#updateEmp').dialog('close');
	//配置增加学生表单
	$("#adEmp").form({
		url:'${pageContext.request.contextPath}/addEmp',
		success:function(data){
			 if(data=="1"){
				$('#addEmp').dialog('close');
				$("#adEmp").form('clear');
				$("#gtid").hide();
					$('#empMsg').datagrid('reload');		
			 }
		}
	});
	
	//配置修改学生表单
		$("#upEmp").form({
			url:'${pageContext.request.contextPath}/updateEmp',
			success:function(data){
				 if(data=="1"){
					$('#updateEmp').dialog('close');
					$("#upEmp").form('clear');
					$.messager.alert('我的消息','更新成功','info',function(){
						$('#empMsg').datagrid('reload');
					});
				 }else{
					 
				 }
			}
		})
	//配置学生数据表格
	$('#empMsg').datagrid({
	    url:'${pageContext.request.contextPath}/findEmp',
	    columns:[[    
	        {field:'checked',checkbox : true,width:150}, 
	        {field:'eid',title:'员工编号',width:150,hidden:true},
	        {field:'ename',title:'员工姓名',width:150},
	        {field:'esex',title:'员工性别',width:150},
	        {field:'ebirthday',title:'员工生日',width:150},
	        {field:'ephone',title:'员工电话',width:150},
	        {field:'esalary',title:'员工工资',width:150},
	    ]],   
	    pagination : true,
	    
	    toolbar : [ {
			iconCls : 'icon-add',
			text : '新增',
			handler : function() {
				$('#addEmp').dialog('open');
				
			}
		}, '-', {
			iconCls : 'icon-remove',
			text : '删除',
			handler : function() {
				$.messager.confirm('提示', '真的要删除吗？', function(r) {
					if (r) {
						var eids='';
						var emps = $("#empMsg").datagrid('getSelections');
						$.each(emps,function(n,v){
							eids=eids+v.eid+','
						})
						//js数组问题
						$.ajax({
							type:'post',
							url:'${pageContext.request.contextPath}/deleteEmp',
							data:{'eids':eids},
							dataType:"text",
							success:function(data){
							   if(data=="1"){
								   $("#empMsg").datagrid('reload'); 
							   }
							}
						})
					}
				})
		
			}
		}, '-', {
			iconCls : 'icon-edit',
			text : '修改',
			handler : function() {
				var emps = $("#empMsg").datagrid('getSelections');
				if (emps.length != 1) {
					$.messager.confirm('提示', '请选择一条数据', function(r) {
						if (r) {
							$("#empMsg").datagrid('unselectAll');
						}
					})
				} else {
					$('#updateEmp').dialog('open');
					var emp = emps[0];
					 $('#upEmp').form('load',emp);

				}
			}
		} ],
		striped : true,
		rownumbers : true,
		
	});  
	
	//配置增加员工信息
$("#ygxm").blur(function(){
	var str1=$("#ygxm").val();
		if((/^[1-9]\d*$|^0$/.test(str1))){
			$("#ygxm1").show();
			$("#qd1").linkbutton({
				disabled:true
			})
		}
		else{
			$("#ygxm1").hide();
		
		}
})	

$("#ygdh").blur(function(){
	var str2=$("#ygdh").val();  
		if((/^[1-9]\d*$|^0$/.test(str2))||str2==""){
			$("#ygdh1").hide();
			$("#qd1").linkbutton({
				disabled:false
			})
		}
		else {
		
			$("#ygdh1").show();	
			$("#qd1").linkbutton({
				disabled:true
			})
		}
})	
$("#yggz").blur(function(){
	var str3=$("#yggz").val();  
		if((/^[1-9]\d*$|^0$/.test(str3))||str3==""){
			$("#yggz1").hide();
			$("#qd1").linkbutton({
				disabled:false
			})
		}
		else{
			
			$("#yggz1").show();
			$("#qd1").linkbutton({
				disabled:true
			})
		} 
		
		
})	


	//配置修改员工信息
$("#upygxm").blur(function(){
	var str=$("#upygxm").val();
		if((/^[1-9]\d*$|^0$/.test(str))){
			$("#ygxm2").show();
			$("#qd2").linkbutton({
				disabled:true
			})
		}
		else{
			$("#ygxm2").hide();
			
		}
})	

$("#upygdh").blur(function(){
	var str=$("#upygdh").val();  
		if((/^[1-9]\d*$|^0$/.test(str))||str==""){
			$("#ygdh2").hide();
			$("#qd2").linkbutton({
				disabled:false
			})
		}
		else{
		
			$("#ygdh2").show();
			$("#qd2").linkbutton({
				disabled:true
			})
		}
})	
$("#upyggz").blur(function(){
	var str=$("#upyggz").val();  
		if((/^[1-9]\d*$|^0$/.test(str))||str==""){
			$("#yggz2").hide();
			$("#qd2").linkbutton({
				disabled:false
			})
		}
		else{
			
			$("#yggz2").show();
			$("#qd2").linkbutton({
				disabled:true
			})
		}
})	




$("#ridshowcid").blur(function(){
	if($("#ridshowcid").val()=="3"){
	 $("#gtid").show();
	}
}) 
     
})
//配置增加表单提交事件
	function addForm() {
		$("#adEmp").form('submit');
	}
//配置更新表单提交事件
	function updateForm() {
		$("#upEmp").form('submit');
	}
</script>
<body>
<input id="searchEmp" class="easyui-searchbox"
		data-options="prompt:'输入姓名查询信息',width:150"></input>
		<table id="empMsg"></table>
		
		<!-- 修改的对话框 -->
	<div id="updateEmp" class="easyui-dialog" title="更新员工信息"
		style="width: 430px; height: 320px;" data-options="modal:true">
		<form id="upEmp" method="post">
			<div style="margin-bottom: 20px;display: none;">
				<span>员工id</span>
				<input class="easyui-textbox" name="eid" style="width: 100%;">
			</div>
			<div style="margin-bottom: 20px">
				<span>员工姓名</span>
				<input id="upygxm"  name="ename" style="width: 160px" maxlength="11"
			   readonly="readonly"><lable id="ygxm2" style="display: none;">您输入的格式不对，请从新输入</lable>
			</div>
			<div style="margin-bottom: 20px" >
				<span>员工性别</span>
				<select class="easyui-combobox" name="esex" readonly="readonly"
					style="width: 50px;">
					<option value="男">男</option>
					<option value="女">女</option>
					<select>
			</div>
			
			<div style="margin-bottom: 20px">
				<span>员工生日</span>
				<input readonly="readonly" name="ebirthday" type="text" class="easyui-datebox" required="required"></input> 
			</div>
			<div style="margin-bottom: 20px;margin-top: 20px">
				<span>员工电话</span>
				<input id="upygdh" name="ephone" style="width: 160px" maxlength="11"
					data-options=""><lable id="ygdh2" style="display: none;">您输入不是数字，请从新输入</lable>
			</div>
			<div style="margin-bottom: 20px">
				<span>员工工资</span>
				<input id="upyggz"  name="esalary" style="width: 160px" maxlength="11"
					data-options="">元&nbsp&nbsp<lable id="yggz2" style="display: none;">您输入的不是数字，请从新输入</lable>
			</div>
		</form>
		<div style="text-align: center; padding: 5px 0">
			<a id="qd2" href="javascript:void(0)" class="easyui-linkbutton"
				onclick="updateForm()" style="width: 80px">提交</a>
		</div>
	</div>
<!-- 增加的对话框 -->
	<div id="addEmp" class="easyui-dialog" title="增加员工信息"
		style="width: 430px; height: 360px;" data-options="modal:true">
		<form id="adEmp" method="post">
			<div style="margin-bottom: 20px;display: none;">
				<span>员工id</span>
				<input class="easyui-textbox" name="eid" style="width: 100%;">
			</div>
			<div style="margin-bottom: 20px">
				<span>员工姓名</span>
				<input id="ygxm"  name="ename" style="width: 160px" maxlength="11"
					data-options=""><lable id="ygxm1" style="display: none;">您输入的格式不对，请从新输入</lable>
			</div>
			<div style="margin-bottom: 20px">
				<span>员工性别</span>
				<select  name="esex"
					style="width: 50px;">
					<option value="男">男</option>
					<option value="女">女</option>
					<select>
			</div>
			
			<div style="margin-bottom: 20px">
				<span>员工生日</span>
				<input name="ebirthday" type="text" class="easyui-datebox" required="required"></input> 
		
			<div style="margin-bottom: 20px;margin-top: 20px">
				<span>员工电话</span>
				<input id="ygdh" name="ephone" style="width: 160px" maxlength="11"
					data-options=""><lable id="ygdh1" style="display: none;">您输入不是数字，请从新输入</lable>
			</div>
			<div style="margin-bottom: 20px">
				<span>角&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp色</span>
				<select id="ridshowcid" name="rid"
					style="width: 100px;">
					<option value="1">总经理</option>
					<option value="2">仓库管理员</option>
					<option value="3">收营员</option>
					<select>
			</div>
			<div style="margin-bottom: 20px">
				<span>员工工资</span>
				<input id="yggz"  name="esalary" style="width: 160px" maxlength="11"
					data-options="">元&nbsp&nbsp<lable id="yggz1" style="display: none;">您输入的不是数字，请从新输入</lable>
			</div>
			<div id="gtid" style="margin-bottom: 20px;  display: none">
				<span>柜台id</span>
				<select  name="cid"
					style="width: 50px;">
					<option value=""></option>
					<option value="1">1</option>
					<option value="2">2</option>
					<option value="3">3</option>
					<option value="4">4</option>
					<option value="5">5</option>
					<option value="6">6</option>
					<option value="7">7</option>
					<select>
			</div>
		</form>
		<div style="text-align: center; padding: 5px 0">
			<a id="qd1" href="javascript:void(0)" class="easyui-linkbutton"
				onclick="addForm()" style="width: 80px">提交</a>
		</div>
	</div>
</body>
</html>